package com.meilishuo.message.interceptors;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lombok.Setter;
import lombok.extern.log4j.Log4j;

import org.eclipse.jetty.util.log.Log;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

@Log4j
@Setter
public class ApiInterceptor extends HandlerInterceptorAdapter {
	
    private List<String> commonList;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String url = request.getRequestURI();
//        Log.debug("url:"+url);
        log.debug("url:" + url);
        request.setCharacterEncoding("UTF-8");

        if (contain(url, commonList)) {
            return true;
        } else {
        	return true;
        }
    }

    private boolean contain(String url, List<String> list) {
        for (String compareUrl : list) {
            if (url.endsWith(compareUrl)) {
                return true;
            }
        }
        return false;
    }

}
